'''
Created on Mar 25, 2012

@author: glenn
'''
import unittest
import os
import json
import zipfile

from converter import *
#from formatter import ZipFormatter, AudioFormatter
#import zipfile

class TestODPConverter(unittest.TestCase):
    def setUp(self):
        #self._odpFileName = "2slide-presentation.odp"
        self._odpFileName = "4slide-presentation.odp"
        base = os.path.splitext(self._odpFileName)[0]
        self._zipFileName = base + ".zip"
        self._htmlZipFileName = base + ".html.zip"
    
#    def test_convertToZippedJSON(self):
#        odpFile = "2slide-presentation.odp"
#        c = ODPConverter()
#        script = c.createScript(odpFile)
#        
#        zipName = "2slide-presentation.zip"
#        f = ZipFormatter(zipName)
#        f.create(script)
#                
#        # by default the output will be "2slide-presentation.zip"
#        self.assertTrue(os.path.exists(zipName), "zip file not created")
#
#        a = AudioFormatter(zipName)
#        a.create(script)
#        
#        # open the file to see what's in it
#        myzip = zipfile.ZipFile(zipName, "r")
#        for info in myzip.infolist():
#            print info.filename, info.date_time, info.file_size, info.compress_size
#            # not sure how to test this
#            
#        myzip.close()
            

#    def test_ODPScriptConverter(self):
#        
#        c = ODPScriptConverter(self._odpFileName, "de")
#        c.convert()
#        
#        print json.dumps(c.script(), indent=2)

#    @unittest.skip("")
#    def test_ODPPngConverter(self):
#        
##        p = ODPPngConverter(self._odpFileName)
##        # p.convert will fail because it needs a script first
##        self.assertRaises(ConverterError, p.convert)
#
#        c = ODPScriptConverter(self._odpFileName, "en")
#        p = ODPPngConverter(self._odpFileName, c)
#        p.convert()
#
#        print json.dumps(p.script(), indent=2)
#
#        p.cleanUp()

    #@unittest.skip("")
    def test_audioConverter(self):
        c = ODPScriptConverter(self._odpFileName, "en")
        a = AudioConverter(c)
        #p = ODPPngConverter(self._odpFileName, a)

        a.convert()
        
        print json.dumps(p.script(), indent=2)
        
    #@unittest.skip("")
    def test_ZippedJSONConverter(self):
        c = ODPScriptConverter(self._odpFileName, "en")
        p = ODPPngConverter(self._odpFileName, c)
        #a = AudioConverter(p)
        z = ZippedJSONConverter(self._zipFileName, p)
        z.convert()
        
        myzip = zipfile.ZipFile(self._zipFileName, "r")
        for info in myzip.infolist():
            print info.filename, info.date_time, info.file_size, info.compress_size
            # not sure how to test this
        myzip.close()

    @unittest.skip("")
    def test_ZippedHTML5Converter(self):
        
        c = ODPScriptConverter(self._odpFileName, "en")
        p = ODPPngConverter(self._odpFileName, c)
        a = AudioConverter(p)
        z = ZippedHTML5Converter(self._htmlZipFileName, os.path.join("..", "templates"), a)
        z.convert()

        #y = ZippedJSONConverter(self._zipFileName, a)
        #y.convert()
        
        myzip = zipfile.ZipFile(self._htmlZipFileName, "r")
        for info in myzip.infolist():
            print info.filename, info.date_time, info.file_size, info.compress_size
            # not sure how to test this
        myzip.close()
    
